<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author YDZ
-->
<template>
  <BasicDrawer
    v-bind="$attrs"
    :showFooter="true"
    :okText="t('订单确认')"
    :okAuth="'puorder:poorder:comfirm'"
    @register="registerDrawer"
    @ok="handleModal"
    width="80%"
  >
    <!-- @ok="handleSubmit" -->
    <template #title>
      <Icon :icon="getTitle.icon" class="m-1 pr-1" />
      <span> {{ getTitle.value }} </span>
    </template>
    <BasicForm @register="registerForm">
      <template #poorderBList>
        <Tabs v-model:activeKey="activeKeytab" tabPosition="top">
          <Tabs.TabPane :key="0" :forceRender="true" :tab="'存货信息'">
            <BasicTable @register="registerTableCh" />
          </Tabs.TabPane>
          <Tabs.TabPane :key="1" :forceRender="true" :tab="'到货信息'">
            <BasicTable @register="registerTableDh" />
          </Tabs.TabPane>
          <Tabs.TabPane :key="2" :forceRender="true" :tab="'执行结果'">
            <BasicTable @register="registerTableZxjg" />
          </Tabs.TabPane>
        </Tabs>

        <!-- <a-button class="mt-2" @click="handlePoorderBAdd" v-auth="'puorder:poorder:edit'">
          <Icon icon="i-ant-design:plus-circle-outlined" /> {{ t('新增') }}
        </a-button> -->
      </template>
    </BasicForm>

    <BasicModal v-bind="$attrs" @register="registerModal" title="订单确认" @ok="handleComfirm">
      <BasicForm @register="registerForm2" />
    </BasicModal>
  </BasicDrawer>
</template>
<script lang="ts" setup name="ViewsPuorderPoorderForm">
  import { ref, unref, computed } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicForm, FormSchema, useForm } from '/@/components/Form';
  import { BasicTable, useTable, BasicColumn } from '/@/components/Table';
  import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
  import { Poorder, poorderSave, poorderForm, poorderComfirm } from '/@/api/srm/puorder/order/poorder';
  import { Tabs } from 'ant-design-vue';
  import { BasicModal, useModal } from '/@/components/Modal';

  const emit = defineEmits(['success', 'register']);

  const { t } = useI18n('puorder.poorder');
  const { showMessage } = useMessage();
  const { meta } = unref(router.currentRoute);
  const record = ref<Poorder>({} as Poorder);
  const activeKeytab = ref<number>(0);

  const getTitle = computed(() => ({
    icon: meta.icon || 'i-ant-design:book-outlined',
    // value: record.value.isNewRecord ? t('新增采购订单') : t('编辑采购订单'),
    value: t('采购订单'),
  }));

  const inputFormSchemas: FormSchema[] = [
    
    {
      label: t('基本信息'),
      field: 'info1',
      component: 'FormGroup',
      colProps: { lg: 24, md: 24 },
    },
    {
      label: t('公司'),
      field: 'unitname',
      component: 'Input',
      componentProps: {
        maxlength: 800,
      },
    },
    {
      label: t('订单编号'),
      field: 'vordercode',
      component: 'Input',
      componentProps: {
        maxlength: 30,
      },
    },
    {
      label: t('版本号'),
      // field: 'nversion',
      field: 'versionDesc',
      component: 'Input',
      componentProps: {
        maxlength: 3,
      },
      rules: [{ pattern: /^\d+$/, message: t('请输入一个正整数') }],
    },
    
    // {
    //   label: t('订单状态'),
    //   field: 'orderStatus',
    //   component: 'Select',
    //   componentProps: {
    //     dictType: 'xy_po_order_status',
    //   },
    // },
    {
      label: t('订单日期'),
      field: 'dorderdate',
      component: 'DatePicker',
      componentProps: {
        format: 'YYYY-MM-DD',
        // showTime: { format: 'HH:mm' },
      },
    },
   
    // {
    //   label: t('业务流程'),
    //   field: 'businame',
    //   component: 'Input',
    //   componentProps: {
    //     maxlength: 2048,
    //   },
    // },
    
    // {
    //   label: t('采购组织'),
    //   field: 'puname',
    //   component: 'Input',
    //   componentProps: {
    //     maxlength: 400,
    //   },
    // },
    
    {
      label: t('供应商'),
      field: 'custName',
      component: 'Input',
      componentProps: {
        maxlength: 400,
      },
    },
    
    
   
    {
      label: t('采购部门'),
      field: 'deptName',
      component: 'Input',
      componentProps: {
        maxlength: 800,
      },
    },
    {
      label: t('采购员'),
      field: 'psnName',
      component: 'Input',
      componentProps: {
        maxlength: 400,
      },
    },

    
  
    {
      label: t('是否最新版'),
      field: 'bislatest',
      component: 'Input',
      componentProps: {
        // maxlength: 1,
      },
    },
    {
      label: t('合计数量'),
      field: 'ntotalnum',
      component: 'Input',
      componentProps: {
        maxlength: 18,
      },
      rules: [
        { pattern: /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/, message: t('请输入一个数值') },
      ],
    },

    {
      label: t('备注信息'),
      field: 'remarks',
      component: 'InputTextArea',
      componentProps: {
        maxlength: 181,
      },
      colProps: { lg: 24, md: 24 },
    },
    {
      label: t('制单信息'),
      field: 'info2',
      component: 'FormGroup',
      colProps: { lg: 24, md: 24 },
    },
    {
      label: t('制单人'),
      field: 'createByName',
      component: 'Input',
      componentProps: {
        maxlength: 400,
      },
    },
    {
      label: t('制单日期'),
      field: 'createDate',
      component: 'DatePicker',
      componentProps: {
        format: 'YYYY-MM-DD',
        // showTime: { format: 'HH:mm' },
      },
    },
    {
      field: 'none',
      component: 'None',
    },
    {
      label: t('修改人'),
      field: 'updateByName',
      component: 'Input',
      componentProps: {
        maxlength: 400,
      },
    },
    {
      label: t('修改日期'),
      field: 'updateDate',
      component: 'DatePicker',
      componentProps: {
        format: 'YYYY-MM-DD',
        // showTime: { format: 'HH:mm' },
      },
    },
    {
      field: 'none',
      component: 'None',
    },
    {
      label: t('审核人'),
      field: 'auditByName',
      component: 'Input',
      componentProps: {
        maxlength: 400,
      },
    },
    {
      label: t('审核日期'),
      field: 'auditDate',
      component: 'DatePicker',
      componentProps: {
        format: 'YYYY-MM-DD',
        // showTime: { format: 'HH:mm' },
      },
    },
    {
      field: 'none',
      component: 'None',
    },
    {
      label: t('确认信息'),
      field: 'info2',
      component: 'FormGroup',
      colProps: { lg: 24, md: 24 },
    },
    {
      label: t('确认人'),
      field: 'puOrderStatus.comfirmByName',
      component: 'Input',
      componentProps: {
        maxlength: 400,
      },
    },
    {
      label: t('确认日期'),
      field: 'puOrderStatus.comfirmDate',
      component: 'DatePicker',
      componentProps: {
        format: 'YYYY-MM-DD',
        // showTime: { format: 'HH:mm' },
      },
    },
    {
      label: t('确认状态'),
      field: 'puOrderStatus.orderStatus',
      component: 'Select',
      defaultValue: '待确认',
      componentProps: {
        dictType: 'srm_order_comfirm_status',
      },
    },
    {
      label: t(''),
      field: 'active',
      component: 'Select',
      componentProps: {
        dictType: 'srm_order_row_active_status',
      },
      show:false
    },
    {
      label: '',
      field: 'detailInfo',
      component: 'Divider',
      colProps: { lg: 24, md: 24 },
    },
    {
      label: t(''),
      field: 'poorderBList',
      component: 'Input',
      colProps: { lg: 24, md: 24 },
      slot: 'poorderBList',
    },
  ];

  const [registerForm, { resetFields, setFieldsValue, updateSchema, validate }] = useForm({
    labelWidth: 120,
    schemas: inputFormSchemas,
    baseColProps: { lg: 8, md: 24 },
    disabled: true,
  });

  const [registerPoorderBTable, poorderBTable] = useTable({
    actionColumn: {
      width: 60,
      actions: (record: Recordable) => [
        {
          icon: 'i-ant-design:delete-outlined',
          color: 'error',
          popConfirm: {
            title: '是否确认删除',
            confirm: handlePoorderBDelete.bind(this, record),
          },
          auth: 'puorder:poorder:edit',
        },
      ],
    },
    rowKey: 'id',
    pagination: false,
    bordered: true,
    size: 'small',
    inset: true,
  });

  // async function setPoorderBTableData(_res: Recordable) {
  //   poorderBTable.setColumns([
  //     {
  //       title: t('行号'),
  //       dataIndex: 'crowno',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 20,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('存货编码'),
  //       dataIndex: 'cinvcode',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 160,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('存货名称'),
  //       dataIndex: 'cinvname',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 400,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('规格'),
  //       dataIndex: 'cinvspec',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 400,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('型号'),
  //       dataIndex: 'cinvtype',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 400,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('计量单位'),
  //       dataIndex: 'measname',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 400,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('数量'),
  //       dataIndex: 'nordernum',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 18,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('是否赠品'),
  //       dataIndex: 'blargess',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 1,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('备注'),
  //       dataIndex: 'remarks',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'InputTextArea',
  //       editComponentProps: {
  //         maxlength: 181,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('计划到货日期'),
  //       dataIndex: 'dplanarrvdate',
  //       width: 215,
  //       align: 'center',
  //       editRow: true,
  //       editComponent: 'DatePicker',
  //       editComponentProps: {
  //         format: 'YYYY-MM-DD HH:mm',
  //         showTime: { format: 'HH:mm' },
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('收货公司'),
  //       dataIndex: 'pkArrvcorp',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 4,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('收货公司名称'),
  //       dataIndex: 'unitname',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 800,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('收货库存组织'),
  //       dataIndex: 'pkArrvstoorg',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 20,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('收货库存组织名称'),
  //       dataIndex: 'bodyname',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 400,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('仓库主键'),
  //       dataIndex: 'cwarehouseid',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 20,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('仓库名称'),
  //       dataIndex: 'storname',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 400,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('收货地区主键'),
  //       dataIndex: 'cdevareaid',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 20,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('收货地区名称'),
  //       dataIndex: 'areaclname',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 400,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('收货地点主键'),
  //       dataIndex: 'cdevaddrid',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 20,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('收货地址'),
  //       dataIndex: 'vreceiveaddress',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 385,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('累计到货数量'),
  //       dataIndex: 'naccumarrvnum',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 18,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('累计入库数量'),
  //       dataIndex: 'naccumstorenum',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 18,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('累计发票数量'),
  //       dataIndex: 'naccuminvoicenum',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 18,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('累计退货数量'),
  //       dataIndex: 'nbackarrvnum',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 18,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('累计退库数量'),
  //       dataIndex: 'nbackstorenum',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 18,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('关闭/打开理由'),
  //       dataIndex: 'closingreason',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 100,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('关闭人'),
  //       dataIndex: 'closeBy',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 20,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('关闭人名称'),
  //       dataIndex: 'closeByName',
  //       width: 130,
  //       align: 'left',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editComponentProps: {
  //         maxlength: 400,
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('关闭日期'),
  //       dataIndex: 'closeDate',
  //       width: 215,
  //       align: 'center',
  //       editRow: true,
  //       editComponent: 'DatePicker',
  //       editComponentProps: {
  //         format: 'YYYY-MM-DD HH:mm',
  //         showTime: { format: 'HH:mm' },
  //       },
  //       editRule: false,
  //     },
  //     {
  //       title: t('删除标志'),
  //       dataIndex: 'dr',
  //       width: 130,
  //       align: 'center',
  //       editRow: true,
  //       editComponent: 'Input',
  //       editRule: false,
  //     },
  //   ]);
  //   poorderBTable.setTableData(record.value.poorderBList || []);
  // }

  function handlePoorderBRowClick(record: Recordable) {
    record.onEdit?.(true, false);
  }

  function handlePoorderBAdd() {
    poorderBTable.insertTableDataRecord({
      id: new Date().getTime(),
      isNewRecord: true,
      editable: true,
    });
  }

  function handlePoorderBDelete(record: Recordable) {
    poorderBTable.deleteTableDataRecord(record);
  }

  async function getPoorderBList() {
    let poorderBListValid = true;
    let poorderBList: Recordable[] = [];
    for (const record of poorderBTable.getDataSource()) {
      if (!(await record.onEdit?.(false, true))) {
        poorderBListValid = false;
      }
      poorderBList.push({
        ...record,
        id: !!record.isNewRecord ? '' : record.id,
      });
    }
    for (const record of poorderBTable.getDelDataSource()) {
      if (!!record.isNewRecord) continue;
      poorderBList.push({
        ...record,
        status: '1',
      });
    }
    if (!poorderBListValid) {
      throw { errorFields: [{ name: ['poorderBList'] }] };
    }
    return poorderBList;
  }

  const tableColumnsCh: BasicColumn[] = [
    {
      title: t('行号'),
      dataIndex: 'crowno',
      width: 60,
      align: 'center',
    },
    {
      title: t('存货编码'),
      dataIndex: 'cinvcode',
      width: 100,
      align: 'left',
    },
    {
      title: t('存货名称'),
      dataIndex: 'cinvname',
      width: 180,
      align: 'left',
    },
    {
      title: t('规格'),
      dataIndex: 'cinvspec',
      width: 100,
      align: 'left',
    },
    {
      title: t('型号'),
      dataIndex: 'cinvtype',
      width: 120,
      align: 'left',
    },
    {
      title: t('计量单位'),
      dataIndex: 'measname',
      width: 70,
      align: 'center',
    },
    {
      title: t('数量'),
      dataIndex: 'nordernum',
      width: 70,
      align: 'center',
    },
     {
      title: t('税率'),
      dataIndex: 'ntaxrate',
      width: 70,
      align: 'center',
    },
    {
      title: t('无税单价'),
      dataIndex: 'fprice',
      width: 80,
      align: 'center',
    },
    {
      title: t('含税单价'),
      dataIndex: 'ftaxprice',
      width: 70,
      align: 'center',
    },
    {
      title: t('税额'),
      dataIndex: 'taxmny',
      width: 80,
      align: 'center',
    },
    {
      title: t('金额'),
      dataIndex: 'fmoney',
      width: 80,
      align: 'center',
    },
    {
      title: t('价税合计'),
      dataIndex: 'ftaxmoney',
      width: 70,
      align: 'center',
    },
    {
      title: t('是否赠品'),
      dataIndex: 'blargess',
      width: 70,
      align: 'center',
    },
    {
      title: t('备注'),
      dataIndex: 'remarks',
      width: 130,
      align: 'left',
    },
  ];

  const tableColumnsDh: BasicColumn[] = [
    {
      title: t('行号'),
      dataIndex: 'crowno',
      width: 60,
      align: 'center',
    },
    {
      title: t('计划到货日期'),
      dataIndex: 'dplanarrvdate',
      width: 100,
      align: 'left',
    },
    {
      title: t('收货公司'),
      dataIndex: 'unitname',
      width: 100,
      align: 'left',
    },
    {
      title: t('收货库存组织'),
      dataIndex: 'bodyname',
      width: 100,
      align: 'left',
    },
    {
      title: t('收货仓库'),
      dataIndex: 'storname',
      width: 100,
      align: 'left',
    },
    {
      title: t('收货地点'),
      dataIndex: 'caddrname',
      width: 100,
      align: 'left',
    },
    {
      title: t('收货地区'),
      dataIndex: 'areaclname',
      width: 100,
      align: 'left',
    },
    {
      title: t('收货地址'),
      dataIndex: 'vreceiveaddress',
      width: 100,
      align: 'left',
    },
  ];

  const tableColumnsZxjg: BasicColumn[] = [
    {
      title: t('行号'),
      dataIndex: 'crowno',
      width: 60,
      align: 'center',
    },
     {
      title: t('订单数'),
      dataIndex: 'nordernum',
      width: 80,
      align: 'center',
    },
    {
      title: t('已准备数'),
      dataIndex: 'puOrderExcute.preShQty',
      width: 80,
      align: 'center',
    },
    {
      title: t('送货中数'),
      dataIndex: 'puOrderExcute.ingShQty',
      width: 80,
      align: 'center',
    },
    {
      title: t('已到货数'),
      dataIndex: 'naccumarrvnum',
      width: 80,
      align: 'center',
    },
    {
      title: t('退货数'),
      dataIndex: 'nbackarrvnum',
      width: 80,
      align: 'center',
    },
    {
      title: t('待送货数'),
      dataIndex: 'puOrderExcute.syQty',
      width: 80,
      align: 'center',
    },
    {
      title: t('累计入库数'),
      dataIndex: 'naccumstorenum',
      width: 80,
      align: 'center',
    },
    {
      title: t('累计退库数'),
      dataIndex: 'nbackstorenum',
      width: 80,
      align: 'center',
    },
   
    // {
    //   title: t('累计到货数量'),
    //   dataIndex: 'naccumarrvnum',
    //   width: 80,
    //   align: 'center',
    // },
    // {
    //   title: t('累计入库数量'),
    //   dataIndex: 'naccumstorenum',
    //   width: 80,
    //   align: 'center',
    // },
    // {
    //   title: t('累计发票数量'),
    //   dataIndex: 'naccuminvoicenum',
    //   width: 80,
    //   align: 'center',
    // },
    // {
    //   title: t('累计退货数量'),
    //   dataIndex: 'nbackarrynum',
    //   width: 80,
    //   align: 'center',
    // },
    // {
    //   title: t('累计退库数量'),
    //   dataIndex: 'nbackstorenum',
    //   width: 80,
    //   align: 'center',
    // },
   
    // {
    //   title: t('删除标志'),
    //   dataIndex: 'dr',
    //   width: 80,
    //   align: 'center',
    // },
    {
      title: t('激活状态'),
      dataIndex: 'bactive',
      dictType: 'srm_order_row_active_status',
      width: 80,
      align: 'center',
    },
    {
      title: t('关闭人'),
      dataIndex: 'closeByName',
      width: 80,
      align: 'left',
    },
    {
      title: t('关闭日期'),
      dataIndex: 'closeDate',
      width: 80,
      align: 'left',
    },
    {
      title: t('关闭/打开理由'),
      dataIndex: 'closingreason',
      width: 120,
      align: 'left',
    },
  ];

  const [registerTableCh, chTable] = useTable({
    rowKey: 'id',
    pagination: false,
    // useSearchForm: true,
    columns: tableColumnsCh,
    // bordered: true,
    // size: 'small',
    // inset: true,
    maxHeight: 300,
    canResize: true,
    showTableSetting: false,
    // immediate: false,
    // showSummary: true,
    // summaryFunc: handleSummaryHz,
  });

  const [registerTableDh, dhTable] = useTable({
    rowKey: 'id',
    pagination: false,
    columns: tableColumnsDh,
    maxHeight: 300,
    canResize: true,
    showTableSetting: false,
  });

  const [registerTableZxjg, zxjgTable] = useTable({
    rowKey: 'id',
    pagination: false,
    columns: tableColumnsZxjg,
    maxHeight: 300,
    canResize: true,
    showTableSetting: false,
  });

  const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
    setDrawerProps({ loading: true });
    await resetFields();
    const res = await poorderForm(data);
    record.value = (res.poorder || {}) as Poorder;
    record.value.__t = new Date().getTime();

    setDrawerProps({ showOkBtn: res.isAllowComfirm });
    setFieldsValue(record.value);
    // setPoorderBTableData(res);
    await chTable.setTableData(record.value.poorderBList || []);
    await dhTable.setTableData(record.value.poorderBList || []);
    await zxjgTable.setTableData(record.value.poorderBList || []);

    // updateSchema([
    //   {
    //     field: 'id',
    //     componentProps: {
    //       disabled: !record.value.isNewRecord,
    //     },
    //   },
    // ]);
    setDrawerProps({ loading: false });
  });


  const [registerForm2, { resetFields:resetFields2, validate:validate2 }] = useForm({
    labelWidth: 80,
    schemas: [
    {
        label: t(''),
        field: 'remarks',
        component: 'InputTextArea',
        componentProps: {
          placeholder: t('请输入确认备注'),
          maxlength: 500,
          rows:5,
          allowClear: true,
        },
        // required: true,
      },
    ],
    baseColProps: { lg: 24, md: 24 },
  });
  const [registerModal, { openModal, closeModal }] = useModal();

  async function handleModal(){
    await openModal(true, {});
    resetFields2();
  }
  
  async function handleComfirm() {
    try {
      closeModal();
      setDrawerProps({ confirmLoading: true });
      let data = await validate2();
      data.selIds = record.value.id
      const res = await poorderComfirm(data);
      showMessage(res.message);
      setTimeout(closeDrawer);
      emit('success', data);
    } catch (error: any) {
      if (error && error.errorFields) {
        showMessage(t('common.validateError'));
      }
      console.log('error', error);
    } finally {
      setDrawerProps({ confirmLoading: false });
    }
  }

  async function handleSubmit() {
    try {
      const data = await validate();
      setDrawerProps({ confirmLoading: true });
      const params: any = {
        isNewRecord: record.value.isNewRecord,
        id: record.value.id,
        dr: record.value.dr,
      };
      data.poorderBList = await getPoorderBList();
      // console.log('submit', params, data, record);
      const res = await poorderSave(params, data);
      showMessage(res.message);
      setTimeout(closeDrawer);
      emit('success', data);
    } catch (error: any) {
      if (error && error.errorFields) {
        showMessage(t('common.validateError'));
      }
      console.log('error', error);
    } finally {
      setDrawerProps({ confirmLoading: false });
    }
  }
</script>
